package cc.xuzhi.muggle.admin.controller;

import cc.xuzhi.muggle.admin.model.SysConfig;
import cc.xuzhi.muggle.admin.service.SysConfigService;
import cc.xuzhi.muggle.common.model.Result;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统配置
 *
 * @author xuzhi
 * @date 2022-05-26 21:20:53
 */
@RestController
@RequestMapping("/sysConfig" )
@Api(tags = "系统配置管理", value = "SysConfigController")
public class SysConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysConfig 系统配置
     * @return
     */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public Result getSysConfigPage(Page page, SysConfig sysConfig) {
        return Result.ok(sysConfigService.page(page, Wrappers.query(sysConfig)));
    }


    /**
     * 通过id查询
     * @param id
     * @return Result
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过id查询")
    public Result getById(@PathVariable("id" ) Long id) {
        return Result.ok(sysConfigService.getById(id));
    }

    /**
     * 新增系统配置
     * @param sysConfig
     * @return Result
     */
    @PostMapping
    @ApiOperation(value = "新增系统配置")
    public Result save(@RequestBody SysConfig sysConfig) {
        return Result.ok(sysConfigService.save(sysConfig));
    }

    /**
     * 修改系统配置
     * @param sysConfig 系统配置
     * @return Result
     */
    @PutMapping
    @ApiOperation(value = "修改系统配置")
    public Result updateById(@RequestBody SysConfig sysConfig) {
        return Result.ok(sysConfigService.updateById(sysConfig));
    }

    /**
     * 通过id删除系统配置
     * @param id
     * @return Result
     */
    @DeleteMapping("/{id}" )
    @ApiOperation(value = "通过id删除系统配置")
    public Result removeById(@PathVariable("id" ) Long id) {
        return Result.ok(sysConfigService.removeById(id));
    }

}
